﻿using System;
using System.Configuration;
using log4net;
using System.Diagnostics;
using System.Reflection;

namespace Demo.CommonBase.Logging
{
    public  class Logger
    {
        public static void Info(string messsage)
        {
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["LoggerInfo"]))
            {
                ILog log = LogManager.GetLogger("DemoLog");
                log4net.Config.XmlConfigurator.Configure();
                log.Info(messsage);
            }
        }
        public static void Error(Exception exception)
        {
            ILog log = LogManager.GetLogger("DemoLog");
            log4net.Config.XmlConfigurator.Configure();
            log.Error(exception.Message, exception);
        }

        public static void Info()
        {
            MethodBase method;
            string result = string.Empty;
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["LoggerInfo"]))
            {
                ILog log = LogManager.GetLogger("DemoLog");
                log4net.Config.XmlConfigurator.Configure();
                StackTrace trace = new StackTrace();
                StackFrame frame =  trace.GetFrame(1);
                if (frame != null)
                {
                    method = frame.GetMethod();
                    if (method != null)
                    {
                       result =  string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name);
                    }
                }
                log.Info(result);
            }
        }
        
    }
}
